package com.Brave.manager.service;

import com.Brave.manager.dao.StudentDao;
import com.Brave.manager.daomian.Student;

public class StudentService {
    StudentDao StudentDao = new StudentDao();
    public boolean isExists(String id) {
        Student[] stus = StudentDao.findAllStudent();
        boolean Exists = false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if(stu != null && stu.getId().equals(id)){
                Exists = true;
                break;
            }
        }
        return  Exists;
    }

    public boolean addStudent(Student stu) {
        return StudentDao.addStudnet(stu);
    }

    public Student[] findAllStudent() {
        Student[] stus = StudentDao.findAllStudent();
        boolean res = false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if(stu != null);
            res = true;
            break;
        }
        if (res){
            return stus;
        }else {
            return null;
        }
    }

    public void deleteStudent(String id) {
        StudentDao.deleteStudent(id);
    }

    public void updateStudent(String id, Student stu) {
        StudentDao.updateStudent(id,stu);
    }
}
